package homework00102;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class Demo4 {

	public static void main(String[] args) {
		int[][] a = {{1, 2},{3, 4, 5,6},{7,8,9,10}};
        trunArray(a);
        for (int i=0;i<a.length;i++) {
        	System.out.print("[");
            	for (int j=0;j<a[i].length;j++){
            		System.out.print(a[i][j]);
            	}
            	System.out.print("]");
            	System.out.println();
        }       
	}

	private static void trunArray(int[][] a) {
		 ArrayList<Integer> arr = new ArrayList<>();
	        for (int i=0;i<a.length;i++) {
	            for (int j=0;j<a[i].length;j++) {
	                arr.add(a[i][j]);
	            }
	        }
	        Random num=new Random();
			for(int i=arr.size()-1;i>0;i--){
				int j=num.nextInt(i+1);
				int temp=arr.get(i);
				arr.set(i, arr.get(j));
	            arr.set(j, temp);
			}
			int index=0;
	        for (int i = 0; i < a.length; i++) {
	            for (int j = 0; j < a[i].length; j++) {
	                a[i][j] = arr.get(index);
	                index++;
	            }
	        }
	}

}
